<?php
require 'libs/rb-mysql.php';

R::setup('mysql:host=43.142.143.8;port=8306;dbname=bot', 'hunk7095', '123456');

//$timezone = R::dispense('timezones');

$timezones = R::findAll('timezones');

$tzMap = [];
foreach ($timezones as $tz) {
    $offset = $tz->offset;
    $offsetList = explode(':', $offset);
    if (count($offsetList) === 2) {
        $offset = $offsetList[0] . '.' . ((intval($offsetList[1]) / 60) * 100);
    }
    if (isset($tzMap[$offset])) {
        continue;
    }

    $offset = str_replace('+', '', $offset);
    $tzMap[$offset] = $tz->tz_id;
}

uksort($tzMap, function ($a, $b) {
    return intval($a*100) - intval($b*100);
});


file_put_contents('tz3.js',
    'const tzMap = ' . json_encode($tzMap, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n");